//
//  TKIMReminListView.m
//  TKIM_标准版
//
//  Created by liupm on 16/5/10.
//  Copyright © 2016年 liupm. All rights reserved.
//

#import "TKIMReminListView.h"
#import "TKIM.h"


@implementation TKIMReminListView

#pragma mark - Table view data source

/**
 *  @Author lpm, 15-10-21 14:10:49
 *
 *  @brief
 *
 *  @param tableView
 *  @param indexPath
 *
 *  @return
 */
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger section = indexPath.section;
    NSArray *list = self.dataList[section-1];
    
    TKIMUITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" ];
    if (!cell)
    {
        cell = [[TKIMUITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    
    TKIMUser *user = list[indexPath.row];
    NSString *name = [TKIMHelper getShowNameWithUser:user];
    cell.title.text = [NSString stringWithFormat:@"%@",name];
    [cell.headView sd_setImageWithURL:[NSURL URLWithString:user.thumbPhotoUrl] placeholderImage:TKIMGetImage(@"im_icon_userDefault")];
    cell.contentView.tag = indexPath.row;
    cell.title.textColor = [TKIMColorHelper stringToColor:@"#616264"];
    cell.title.font = [UIFont systemFontOfSize:15.5f];
    return cell;
}


/**
 *  @Author lpm, 15-10-21 14:10:57
 *
 *  @brief
 *
 *  @param tableView
 *  @param indexPath
 */
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSInteger section = indexPath.section;
    NSArray *list = self.dataList[section-1];
    TKIMUser *user = list[indexPath.row];
    if (self.delegate && [self.delegate respondsToSelector:@selector(toChat:)])
    {
        [self.delegate toChat:user];
    }
}


/**
 *  @Author lpm, 16-05-10 15:05:22
 *
 *  @brief  刷新
 *
 *  @param dataArray
 */
-(void)reloadData:(NSMutableArray *)dataArray
{
    [super reloadData:dataArray];
    if (!dataArray||dataArray.count == 0)
    {
        self.footLabel.text = @"暂无联系人";
    }
    else
    {
        self.footLabel.text = [NSString stringWithFormat:@"%ld位联系人",(unsigned long)dataArray.count];
    }
}

@end
